package com.wzdigit.wms.raw.service.mid;

import com.wzdigit.wms.basic.domain.basic.Warehouse;
import com.wzdigit.wms.basic.domain.mapping.CodeMapping;
import com.wzdigit.wms.basic.mapper.core.basic.WarehouseMapper;
import com.wzdigit.wms.basic.service.code.CodeMappingService;
import com.wzdigit.wms.raw.domain.dto.HouseQaStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
    * 查询SAP仓库编码对应的WMS仓库ID
    * @author shuaic
    * @date 2021/7/28 15:02
*/
@Service
@Slf4j
public class MappingHouseService {
	
	@Autowired
	CodeMappingService codeMappingService;

	@Autowired
	WarehouseMapper warehouseMapper;

	public HouseQaStatus getWmsHourseIdBySapHourseCode(String sapHouseCode) {
		// 处理仓库信息
		CodeMapping codeMapping = codeMappingService.selectByMappingCode(sapHouseCode);
		if (codeMapping == null) {
			return null;
		}
		// 查询仓库ID//
		Warehouse warehouse = warehouseMapper.selectOneByWhsCode(codeMapping.getWmsCode());
		if (warehouse == null) {
			return null;
		}
		HouseQaStatus houseQaStatus = new HouseQaStatus();
		houseQaStatus.setWhsId(warehouse.getWhsId());
		houseQaStatus.setQaStatus(codeMapping.getQaStatus());
		return houseQaStatus;
	}

	public String getSapHouseByWhsId(Integer whsId, String factory) {
		Warehouse warehouse = warehouseMapper.selectById(whsId);
		CodeMapping codeMapping = codeMappingService.selectByWhsCodeAndFactoryOrQaStatus(factory, warehouse.getWhsCode(), null);
		return codeMapping.getMappingCode();
	}
}
